<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{ item }}</li>
  </ul>
  <ul>
    <li v-for="item in productArr">{{ item }}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>序号</th>
      <th>商品标题</th>
      <th>商品价格</th>
      <th>商品数量</th>
    </tr>
    <tr v-for="(pro,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{pro.title}}</td>
      <td>{{pro.price}}</td>
      <td>{{pro.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";
import index from "vuex";

let productArr = ref([
  {title: '小米14', price: 8000, num: 500},
  {title: '魅族60', price: 2000, num: 600},
  {title: '华为P50', price: 5000, num: 1000},
  {title: 'iphone14', price: 10000, num: 2000},
  {title: 'opporeno10', price: 3000, num: 300},
  {title: 'vivo x60', price: 4000, num: 400}
]);
//定义删除的方法
const del = (index)=>{
  if (confirm('你确认要删除此商品吗？')){
    productArr.value.splice(index,1)
  }
}

</script>


<style scoped>

</style>